package com.spr.gw.service.impl;

import com.spr.gw.common.ResponseCode;
import com.spr.gw.common.ResultBean;
import com.spr.gw.entity.SystemConfig;
import com.spr.gw.mapper.SystemConfigMapper;
import com.spr.gw.service.SystemConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
class SystemConfigServiceImpl implements SystemConfigService {

    @Autowired
    private SystemConfigMapper systemConfigMapper;

    public ResultBean<SystemConfig> findSystemConfig(){
        List<SystemConfig> list = systemConfigMapper.selectAll();
        return ResultBean.createBySuccess(list.get(0));
    }

    public ResultBean updateSystemConfig(SystemConfig systemConfig) {
        systemConfig.setId(1);
        int i = systemConfigMapper.updateByPrimaryKeySelective(systemConfig);
        if(i != 1){
            return ResultBean.createByCodeMessage(ResponseCode.UPDATE_ERROR.getCode(),ResponseCode.UPDATE_ERROR.getDesc());
        }
        return  ResultBean.createBySuccess("更新成功");
    }
}
